package exception;

import java.io.EOFException;
import java.io.FileNotFoundException;

/**
 * @Author:Cjj
 * @Date:2025/6/18
 *
 */
public class ThrowableCheckTest {
    public void test(boolean flag)throws FileNotFoundException, EOFException{
        //读取文件之前，获取文件地址
        //读取文件
        //文件是否存在
        if(flag){
          throw new FileNotFoundException("文件不存在");
        }else {
            throw new EOFException("文件超过最大限制");


        }
    }

    public void readFile()throws FileNotFoundException, EOFException{
        try{
            test(true);
        }catch (FileNotFoundException e){
            throw  new EOFException(e.getMessage());
        }catch (EOFException e){
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        ThrowableCheckTest test = new ThrowableCheckTest();
        System.out.println("异常捕获前的逻辑");
        try{
            test.readFile();
        }catch (Exception e){
            e.printStackTrace();;
        }finally{
            System.out.println("执行finally子句");
        }
        System.out.println("异常捕获后的逻辑");
    }
}
